using System;
using System.ComponentModel;

using DevExpress.Xpo;
using DevExpress.Data.Filtering;

using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.ExpressApp.Editors;

namespace SCMSolution.Module
{
    [AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
    public class AutoCreatableObjectAttribute : Attribute
    {
        private bool autoCreatable = true;
        private ViewEditMode viewEditMode = ViewEditMode.Edit;
        public AutoCreatableObjectAttribute()
        {
        }
        public AutoCreatableObjectAttribute(bool autoCreatable)
        {
            this.autoCreatable = autoCreatable;
        }
        public bool AutoCreatable
        {
            get { return autoCreatable; }
        }
        public ViewEditMode ViewEditMode
        {
            get { return viewEditMode; }
            set { viewEditMode = value; }
        }

    }

    public class AutoCreatableObjectController : ViewController<DetailView>
    {

        protected override void OnViewChanging(View view)
        {
            base.OnViewChanging(view);
            Active.SetItemValue("AutoCreatableObject", false);
            if (view != null)
            {
                AutoCreatableObjectAttribute attribute = view.ObjectTypeInfo.FindAttribute<AutoCreatableObjectAttribute>(true);
                if (attribute != null)
                {
                    Active.SetItemValue("AutoCreatableObject", true);
                }
            }
        }
    }

}
